package com.softtek.exception;

public class JBException extends Exception{
	private static final long serialVersionUID = -559628810359228726L;

	private transient Throwable cause;

	private transient String user_message;


	/**
	 * Constructs a BDException with the specified detail message
	 * 
	 * @param message - String
	 */
	public JBException(final String message)
	{
		super();
		this.user_message = message;
	}

	/**
	 * Constructs a BDException with the specified message and wrappers lower
	 * level exceptions.
	 * 
	 * @param message - String
	 * @param cause - Throwable
	 */
	public JBException(final String message, final Throwable cause)
	{
		super();
		this.user_message = message;
		this.cause = cause;
	}

	/**
	 * Obtains the lower level exception that caused the BDException
	 * 
	 * @return Throwable
	 */
	public Throwable getCause()
	{
		return this.cause;
	}

	/**
	 * Obtains the message that should be displayed to the user
	 * 
	 * @return  String
	 */
	public String getUserMessage()
	{
		return this.user_message;
	}

	/**
	 * Prints the Exception Stack Trace on the standard error stream
	 */
	public void printStackTrace()
	{
		super.printStackTrace();
		if (cause != null)
		{
			System.err.println("Caused by:");
			cause.printStackTrace();
		}
	}

	/**
	 * Prints the Exception Stack Trace on the PrintStream
	 * 
	 * @param ps - PrintStream
	 */
	public void printStackTrace(final java.io.PrintStream ps)
	{
		super.printStackTrace(ps);
		if (cause != null)
		{
			ps.println("Caused by:");
			cause.printStackTrace(ps);
		}
	}

	/**
	 * Prints the Exception Stack Trace on the PrintWriter
	 * 
	 * @param pw - PrintWriter
	 */
	public void printStackTrace(final java.io.PrintWriter pw)
	{
		super.printStackTrace(pw);
		if (cause != null)
		{
			pw.println("Caused by:");
			cause.printStackTrace(pw);
		}
	}
}
